/*
 * @Author: 彭林
 * @Date: 2020-12-25 11:46:02
 * @LastEditTime: 2021-07-01 15:19:54
 * @LastEditors: 彭林
 * @Description:
 * @FilePath: /src/saas-app/app/api/v1/course.go
 */
package v1

import (
	"saas-app/app/define"
	"saas-app/app/service"
	"saas-app/library/response"

	"github.com/gogf/gf/net/ghttp"
)

func GetCourseList(r *ghttp.Request) {

	var CourseParams *define.CourseParams
	if err := r.Parse(&CourseParams); err != nil {
		response.JsonExit(r, 1, err.Error())
	}

	result, total := service.CourseService().GetCourseList(CourseParams)

	response.JsonExit(r, 0, "ok", response.Paging(result, total, CourseParams.Page, CourseParams.Limit))
}

func CheckCourse(r *ghttp.Request) {
	var paikeParam []*define.PaikeParam
	if err := r.Parse(&paikeParam); err != nil {
		response.JsonExit(r, 1, err.Error())
	}
	paikeParams := service.CourseService().CheckCourse(paikeParam)
	response.JsonExit(r, 0, "ok", paikeParams)
}

func AddCourse(r *ghttp.Request) {
	var paikeParam []*define.PaikeParam
	if err := r.Parse(&paikeParam); err != nil {
		response.JsonExit(r, 1, err.Error())
	}

	for _, item := range paikeParam {
		item.SchoolID = r.GetCtxVar("school_id").Int()
		item.CampusID = r.GetCtxVar("campus_id").Int()
	}

	service.CourseService().AddCourse(paikeParam)
	response.JsonExit(r, 0, "ok", nil)
}
